<template>
  <el-dialog
    top="30px"
    width="900px"
    append-to-body
    title="编辑信息"
    :close-on-click-modal="false"
    :before-close="beforeClose"
    :visible.sync="visible"
  >
    <table class="table table-bordered table-sm bg-white table-vertical-middle text-center">
      <tr>
        <td class="text-left font-weight-bold" data-font-bold="true" colspan="6">
          {{ labelKey[submitKey] }}
        </td>
      </tr>
      <tr>
        <td colspan="6" class="report-input-td">
          <div class="emp-line">
            <el-input
              type="textarea"
              v-model="hotel[submitKey]"
              placeholder="请输入"
              :rows="6"
            ></el-input>
          </div>
        </td>
      </tr>
    </table>
    <div class="text-center mt-5">
      <el-button type="primary" class="btn-long" :loading="saveLoading" @click="handleConfirm">
        保存
      </el-button>
      <el-button class="btn-long" :loading="saveLoading" @click="beforeClose">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  components: {},
  props: {
    visible: Boolean,
    submitKey: String,
    hotelData: { type: Object, default: () => {} },
  },
  data() {
    return {
      labelKey: {
        bus_history_des: '九、经营历史/个人履历描述',
        stock_des: '十、股权结构及经营情况描述',
        loan_reason_des: '十一、贷款目的和原因及申请额度的合理性描述分析',
        return_des: '十三、还款能力分析',
        gua_method_des: '十四、反担保措施',
        invest_result: '十五、调查结论和意见',
      },
      hotel: {},
      saveLoading: false,
      hotelTable: 'credit_industrial_hotel_invest',
    }
  },
  computed: {},
  watch: {
    hotelData: {
      handler: function () {
        this.hotel = { ...this.hotelData }
      },
      immediate: true,
      deep: true,
    },
  },
  created() {},
  mounted() {},
  methods: {
    handleConfirm() {
      if (!this.hotel.id) {
        return
      }
      const data = {}
      data[this.submitKey] = this.hotel[this.submitKey]
      this.saveLoading = true
      this.$api
        .updateData(this.$serviceName, this.hotelTable, this.hotel.id, data)
        .then(() => {
          this.$message.success('保存成功')
          this.handlerSuccess()
          this.beforeClose()
        })
        .catch(err => {
          this.$message.error(err?.data?.error_description || '保存失败，请重试！')
        })
        .finally(() => {
          this.saveLoading = false
        })
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
    handlerSuccess() {
      this.$emit('success', true)
    },
  },
}
</script>

<style lang="scss" scoped>
.report-input-td {
  background-color: #ffffee;
}
</style>
